package com.lj.demo.springbootshirojwt.controller;

import com.lj.demo.springbootshirojwt.entity.ResponseResult;
import com.lj.demo.springbootshirojwt.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Title: 用户controller
 * Description:
 * Date: 2019年06月24日 14:29
 *
 * @author lvjie@hiynn.com
 * @version 1.0
 * Significant Modify：
 * Date                  Author                 Content
 * =================================================================
 * 2019年06月24日         lvjie@hiynn.com         创建文件,实现基本功能
 * =================================================================
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 登录
     * @param param 用户名 密码
     * @return token+user
     */
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResponseResult login(@RequestBody Map<String,String> param){
        Map<String,Object> result = userService.login(param.get("userName"), param.get("password"));
        return ResponseResult.success(result);
    }

    /**
     * 登出
     * @return
     */
    @RequestMapping(value = "/logout",method = RequestMethod.GET)
    public ResponseResult logout(){
        userService.logout();
        return ResponseResult.success("success");
    }

    /**
     * 没登录处理
     * @return
     */
    @RequestMapping(value = "/notLogin",method = RequestMethod.GET)
    public ResponseResult notLogin(){
        return ResponseResult.fail("请重新登录");
    }

    /**
     * 处理权限不足
     * @return
     */
    @RequestMapping(value = "/unauthorized",method = RequestMethod.GET)
    public ResponseResult unauthorized(){
        return ResponseResult.fail("权限不足");
    }
}
